package com.note.common.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * 文件记录实体类
 * 对应数据库中的file_record表
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "file_record")
@TableName("file_record")
@Schema(description = "文件记录数据模型")
public class FileRecord extends BaseEntity {

    @Id
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "文件ID(自增主键)", example = "1")
    private Long id;

    @Column(nullable = false)
    @TableField
    @Schema(description = "用户ID", example = "1")
    private Long userId;

    @Column(nullable = false)
    @TableField
    @Schema(description = "文件名", example = "image.jpg")
    private String fileName;

    @Column(nullable = false)
    @TableField
    @Schema(description = "原始文件名", example = "original-image.jpg")
    private String originalFileName;

    @Column(nullable = false)
    @TableField
    @Schema(description = "文件URL", example = "http://minio.example.com/bucketname/objectname")
    private String url;

    @Column(nullable = false)
    @TableField
    @Schema(description = "文件大小(字节)", example = "1024")
    private Long fileSize;

    @Column(nullable = false)
    @TableField
    @Schema(description = "文件类型", example = "image/jpeg")
    private String contentType;
    
    @Column
    @TableField
    @Schema(description = "文件MD5", example = "d41d8cd98f00b204e9800998ecf8427e")
    private String fileMd5;
    
    @Column
    @TableField
    @Schema(description = "存储桶名称", example = "user-avatar")
    private String bucketName;
    
    @Column
    @TableField
    @Schema(description = "对象键名", example = "20250501/uuid-username.jpg")
    private String objectName;
    
    @Column
    @TableField
    @Schema(description = "关联业务ID", example = "note-123")
    private String businessId;
    
    @Column
    @TableField
    @Schema(description = "文件状态 0:临时 1:永久", example = "1")
    private Integer status = 1;

    @TableField
    @Schema(description = "删除标记 0:正常 1:删除", example = "0")
    private Integer deleted = 0;

    @Column(name = "created_at")

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 修正月份MM和小时HH的大小写
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") // 修正时区写法
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    @Schema(description = "创建时间", example = "2023-10-01T12:00:00")
    private LocalDateTime createdAt;

    @Column(name = "updated_at")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 修正月份MM和小时HH的大小写
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") // 修正时区写法
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间", example = "2023-10-01T12:00:00")
    private LocalDateTime updatedAt;
} 